﻿Imports System.Drawing
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports Camstar.WebClient.FormsBuilder.WebForm
Imports Camstar.WebClient.WebServicesProxy.InSiteWebServices
Imports System.IO
Imports Camstar.WebClient.WebConstants
Imports BusinessRule.IBusiness
Imports BusinessRule.DTO
Imports BusinessRule.BusinessFactory
Imports BusinessRule.Common

Partial Class ExchangeInfoPrintPopup
    Inherits System.Web.UI.Page

    Private oIBusiness As uLMSExchangeBillIbusiness = uMESBusinessFactory.instance.GetuLMSExchangeBillObject()
    Public strProductName As String
    Public htmlstr As String
    Public strHtmlTable As String
    Public Shared PrintType As String
    Public Shared strEName As String

    Public tempExchangeID As String = ""

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If IsNothing(Session("ExchangeIDForPrint")) = False Then
                Dim para As Dictionary(Of String, String) = Session("ExchangeIDForPrint")
                Session.Remove("ExchangeIDForPrint") ' add YangJiang 去掉Session中的ExchangeIDForPrint
                If para("Type").ToString = String.Empty Then
                    Response.Write("<script type='text/javascript'>alert('没有选择要打印串件单或周转单');window.close();</script>")
                    Return
                Else
                    Dim ExchangeIDList As String = para("ExchangeID")
                    strHtmlTable = String.Empty
                    PrintType = para("Type").ToString
                    If ExchangeIDList.Contains(",") Then
                        For Each Str As String In ExchangeIDList.Split(",")
                            If String.IsNullOrEmpty(Str) Then
                                Continue For
                            End If
                            tempExchangeID = Str
                            iniPate(Str)
                        Next
                    Else
                        tempExchangeID = ExchangeIDList
                        iniPate(ExchangeIDList)
                    End If
                End If
            Else
                Response.Write("<script type='text/javascript'>alert('没有选择要打印串件单或周转单');window.close();</script>")
                Return
            End If
        End If
    End Sub

    Private Sub iniPate(ByVal ExchangeID As String)
        Dim strHtmlTableMain As String
        Dim strHtmlTableDetails As String

        Dim dic As New Dictionary(Of String, String)
        dic.Add("ExchangeID", ExchangeID)
        dic.Add("PageSize", 1)
        dic.Add("CurrentPageIndex", 1)
        Dim PR As uMESProcessResult = oIBusiness.SearchContainerNoInfo(dic)

        strHtmlTableMain = SetTableMain(PR)
        strHtmlTableDetails = SetTableDetail(PR)

        strHtmlTable = String.Format("{0}{1}", strHtmlTableMain, strHtmlTableDetails)
    End Sub

    Private Function SetTableMain(ByVal PR As uMESProcessResult) As String
        Dim dt As DataTable = PR.DBTable
        strEName = dt.Rows(0)("exchangename").ToString
        Dim strPName As String = dt.Rows(0)("productname").ToString
        Dim strCName As String = dt.Rows(0)("containername").ToString
        Dim strComCName As String = dt.Rows(0)("comContainername").ToString
        Dim strPdesc As String = dt.Rows(0)("description").ToString
        Dim strCDate As String = dt.Rows(0)("createdate").ToString.Substring(0, 9)
        Dim strMachine As String = dt.Rows(0)("MachineName").ToString 'update YangJiang 20180529 machine->MachineName
        Dim strProperty As String = dt.Rows(0)("BillProperty").ToString

        Dim strSource As String = dt.Rows(0)("BillSource").ToString
        Dim strWorkhours As String = dt.Rows(0)("Workhours").ToString
        Dim strReason As String = dt.Rows(0)("Reason").ToString
        Dim strMapRequest As String = dt.Rows(0)("MapRequest").ToString

        '获取厂内确认，厂外确认会签信息
        '厂内确认人=主管生产厂长 ，检验检测事业部 分厂代码613，工程技术部 208，生产指挥部 402，顾客代表 633(暂定)
        Dim dtSign As DataTable = oIBusiness.GetExchangeBillSign(tempExchangeID)

        '主管生产厂长
        Dim strLeader As String = "", strChecker As String = "", strEngineer As String = "", strOperator As String = "", strCustomer As String = ""
        If dtSign.Select("BILLSTATUS='2'").Length > 0 Then
            strLeader = dtSign.Select("BILLSTATUS='2'")(0)("fullname").ToString()
        End If

        '检验检测事业部
        If dtSign.Select("BILLSTATUS='3' and factoryCode='613'").Length > 0 Then
            strChecker = dtSign.Select("BILLSTATUS='3' and factoryCode='613' ")(0)("fullname").ToString()
        End If

        '工程技术部
        If dtSign.Select("BILLSTATUS='3' and factoryCode='208'").Length > 0 Then
            strEngineer = dtSign.Select("BILLSTATUS='3' and factoryCode='208' ")(0)("fullname").ToString()
        End If

        '生产指挥部
        If dtSign.Select("BILLSTATUS='3' and factoryCode='402'").Length > 0 Then
            strOperator = dtSign.Select("BILLSTATUS='3' and factoryCode='402' ")(0)("fullname").ToString()
        End If

        '顾客代表
        If dtSign.Select("BILLSTATUS='3' and factoryCode='633'").Length > 0 Then
            strCustomer = dtSign.Select("BILLSTATUS='3' and factoryCode='633' ")(0)("fullname").ToString()
        End If

        Dim sbhtml As New StringBuilder
        'update YangJiang 20180531
        If PrintType = "0" Then
            sbhtml.AppendLine("<div  style=' width:900px; height:auto;margin-top:90px;' align='center'>")
            'sbhtml.AppendLine("<div style=' width:850px; float:left; height:auto;' >")
            sbhtml.AppendLine("<table width='900' border='0' ><tr><td colspan='2' align='center' style='border-bottom:0px;font-size:30px;'>零件串件单</td>")
            sbhtml.AppendLine("</tr><tr><td class='bh'>" + "编号:  " + strEName + "</td></tr></table>")
            sbhtml.AppendLine("<table width='850'  style='text-align:center' id='tab1' ><tr><td width='150'  height='120px' >件号</td>")
            sbhtml.AppendLine("<td colspan='2' >" + strPName + "</td><td width='150'>组合件号</td><td width='275'>" + strComCName + "</td></tr><tr ><td  height='120px'>名称</td>")
            sbhtml.AppendLine("<td colspan='2'>" + strPdesc + "</td><td>串件日期</td><td>" + strCDate + "</td></tr><tr><td  height='120px'>串上机号</td><td colspan='2'>" + strMachine + "</td>")
            sbhtml.AppendLine("<td>串件性质</td><td>" + strProperty + "</td></tr><tr><td  height='120px'>零件来源</td><td colspan='2'>" + strSource + "</td><td>工作时间</td>")
            sbhtml.AppendLine("<td>" + strWorkhours + "</td></tr><tr><td  height='120px' >串件原因</td><td colspan='4'>" + strReason + "</td></tr><tr><td rowspan='2'>主要要求</td>")
            sbhtml.AppendLine("<td width='70' height='140px'>图纸要求</td><td colspan='3' >" + strMapRequest + "</td></tr><tr><td  height='140px'>实际</td>")
            sbhtml.AppendLine("<td colspan='3'></td></tr><tr><td  height='100px'>主管生产厂长</td><td colspan='2'>" + strLeader + "</td><td>检验检测事业部</td>")
            sbhtml.AppendLine("<td>" + strChecker + "</td></tr><tr><td  height='100px'>工程技术部/技术中心</td>" + strEngineer + "<td colspan='2'></td><td>生产指挥部</td>" + strOperator + "<td></td></tr>")
            sbhtml.AppendLine("<tr><td  height='100px'>顾客代表</td><td colspan='4'>" + strCustomer + "</td></tr><tr><td  height='130px'>备注</td>")
            sbhtml.AppendLine("<td colspan='4'></td></tr></table></div>")
        Else
            sbhtml.AppendLine("<div  style='width:900px; height:auto;margin-top:90px;' align='center'>")
            'sbhtml.AppendLine("<div style=' width:850px; float:left; height:auto;' >")
            sbhtml.AppendLine("<table width='900' border='0'><tr><td align='center' style='border-bottom:0px;font-size:30px;'>零件周转通知单</td>")
            sbhtml.AppendLine("</tr><tr><td class='bh'>" + "编号:  " + strEName + "</td></tr></table>")
            sbhtml.AppendLine("<table width='860' id='tab1' ><tr><td width='160' height='120px'>件号</td><td width='265'>" + strPName + "</td>")
            sbhtml.AppendLine("<td width='150'>组合件号</td><td width='265'>" + strComCName + "</td></tr><tr><td height='120px'>名称</td><td>" + strPdesc + "</td>")
            sbhtml.AppendLine("<td>日期</td><td>" + strCDate + "</td></tr><tr><td height='120px'>机号</td><td>" + strMachine + "</td><td>零件来源</td><td>" + strSource + "</td></tr>")
            sbhtml.AppendLine("<tr class='dd'><td colspan='4' height='50px' style='text-align:left;border-bottom:0px; border-bottom:0;'>周转原因： </td></tr>")
            sbhtml.AppendLine("<tr class='dd'><td colspan='4' height='450px' class='dd' style='border-top:0;text-align:left;word-wrap:break-word'>" + strReason + "</td></tr><tr><td height='120px'>主管生产厂长</td><td>" + strLeader + "</td>")
            sbhtml.AppendLine("<td>检验检测事业部</td><td>" + strChecker + "</td></tr><tr><td height='110px'>工程技术部/技术中心</td><td>" + strEngineer + "</td><td>生产指挥部</td>")
            sbhtml.AppendLine("<td>" + strOperator + "</td></tr><tr><td height='110px'>顾客代表</td><td colspan='3'>" + strCustomer + "</td></tr><tr><td height='120px'>备注</td>")
            sbhtml.AppendLine("<td colspan='3'></td></tr></table></div>")
        End If

        SetTableMain = sbhtml.ToString()
    End Function

    Private Function SetTableDetail(ByVal PR As uMESProcessResult) As String
        SetTableDetail = String.Empty
    End Function

End Class
